import { create } from '@zh/common-utils/http'

const application = create(process.env.VUE_APP_API_MOLI_APPLICATION)

const adapter = create(process.env.VUE_APP_API_ZONGHENG_ADAPTER)

function serve (service) {
  if (service == 'adapter') {
    return adapter
  } else if (service == 'application') {
    return application
  }
}

export function findPersion (service) {
  return serve(service).get(`/user/userUnitRoleInfo`)
}
export function findSubPersion (service, params) {
  return serve(service).get(`/user/child/userUnit?id=${params.id}&type=${params.type}`)
}

/**
 * 根据人员ID查询人员信息
 * @param {*} id   userIds
 * @returns
 */
export function getTreeUnitUsersByUserIds (service, userId) {
  return serve(service).post(`/user/list/by/ids`, { userIds: userId })
}

/**
 * 根据机构ID查询机构信息
 * @param {*} id   userIds
 * @returns
 */
export function getTreeUnitListByUserIds (service, unitId) {
  return serve(service).post(`/unit/list/by/ids`, { unitIds: unitId })
}

/**
 * 根据角色ID查询角色信息
 * @param {*} id   userIds
 * @returns
 */
export function getRole (service, roleId) {
  return serve(service).post(`/role/getRoleListByIds`, { roleIds: roleId })
}

/**
 * 查询表单权限数据
 * @param {*} id   userIds
 * @returns
 */
export function member (applicationId) {
  return application.get(`/find/member?applicationId=${applicationId}`)
}

/**
 * 查询表单内权限数据
 * @param {*} id   userIds
 * @returns
 */
export function permission (formId) {
  return application.get(`/menu/find/permissionByFormId?formId=${formId}`)
}

/**
 * 查询数据接口
 * @param {*} id   userIds
 * @returns
 */
export function conditionSearch (name, applicationId, formId) {
  return application.get(`/list/info/by/conditionSearch?name=${name}&applicationId=${applicationId}&formId=${formId}`)
}